home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / edit / thesrc20.zip / trace.c < prev    next >
C/C++ Source or Header  |  1995-01-26  |  3KB  |  114 lines

  1. /*
  2.  * THE - The Hessling Editor. A text editor similar to VM/CMS xedit.
  3.  * Copyright (C) 1991-1995 Mark Hessling
  4.  * 
  5.  * This program is free software; you can redistribute it and/or
  6.  * modify it under the terms of the GNU General Public License as
  7.  * published by the Free Software Foundation; either version 2 of
  8.  * the License, or any later version.
  9.  * 
  10.  * This program is distributed in the hope that it will be useful,
  11.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13.  * General Public License for more details.
  14.  * 
  15.  * You should have received a copy of the GNU General Public License
  16.  * along with this program; if not, write to:
  17.  * 
  18.  *    The Free Software Foundation, Inc.
  19.  *    675 Mass Ave,
  20.  *    Cambridge, MA 02139 USA.
  21.  * 
  22.  * 
  23.  * If you make modifications to this software that you feel increases
  24.  * it usefulness for the rest of the community, please email the
  25.  * changes, enhancements, bug fixes as well as any and all ideas to me.
  26.  * This software is going to be maintained and enhanced as deemed 
  27.  * necessary by the community.
  28.  *
  29.  * Mark Hessling                     email: M.Hessling@gu.edu.au
  30.  * 36 David Road                     Phone: +61 7 849 7731
  31.  * Holland Park                      Fax:   +61 7 875 5314
  32.  * QLD 4121
  33.  * Australia
  34.  */
  35.  
  36. /*
  37. $Id: trace.c 2.0 1995/01/26 16:32:16 MH Release MH $
  38. */
  39.  
  40. #include <stdlib.h>
  41. #include <stdio.h>
  42. #include <stdarg.h>
  43. void trace_initialise();
  44. void trace_function();
  45. void trace_return();
  46. void trace_string(char *,...);
  47.  
  48. char trace_save_str[40];
  49. char trace_env[40];
  50. FILE *trace_fp;
  51. short trace_number,trace_level=(-1);
  52.  
  53. void trace_initialise()
  54. {
  55.  char *trace_env_ptr=getenv("TRACE");
  56.  
  57.  trace_fp = NULL;
  58.  if (trace_env_ptr == NULL)
  59.     return;
  60.  strcpy(trace_env,trace_env_ptr);
  61.  trace_number = trace_level = 0;
  62.  return;
  63. }
  64. void trace_function(trace_str)
  65. char *trace_str;
  66. {
  67.  
  68.  register int i;
  69.  if (trace_level == (-1))
  70.     return;
  71.  if (strcmp(trace_str,trace_save_str) == 0)
  72.    {
  73.     trace_number++;
  74.     trace_level++;
  75.     return;
  76.    }
  77.  trace_fp = fopen(trace_env,"a");
  78.  fprintf(trace_fp,"%5d\n",trace_number);
  79.  for (i=0;i<trace_level;i++)
  80.      fprintf(trace_fp,"  ");
  81.  fprintf(trace_fp,"(%d)%-s",trace_level,trace_str);
  82.  for (i=0;i<60-(trace_level*2)-strlen(trace_str);i++)
  83.      fprintf(trace_fp," ");
  84.  
  85.  trace_number = 1;
  86.  trace_level++;
  87.  fclose(trace_fp);
  88.  strcpy(trace_save_str,trace_str);
  89.  return;
  90. }
  91. void trace_return()
  92. {
  93.  if (trace_level == (-1))
  94.     return;
  95.  trace_level--;
  96.  if (trace_level < 0)
  97.     fprintf(trace_fp,"****** trace level below zero ********");
  98.  
  99.  return;
  100. }
  101. void trace_string(char *fmt,...)
  102. {
  103.  va_list args;
  104.  
  105.  if (trace_level == (-1))
  106.     return;
  107.  va_start(args,fmt);
  108.  trace_fp = fopen(trace_env,"a");
  109.  vfprintf(trace_fp,fmt,args);
  110.  fclose(trace_fp);
  111.  va_end(args);
  112.  return;
  113. }
  114.